package com.um2.mauction.java;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.DynaActionForm;

public class FrmAjoutProduitParticulier2Bean extends DynaActionForm 
{
	private static final long serialVersionUID = 1L;

	public ActionErrors validate(ActionMapping arg0, HttpServletRequest arg1) 
	{
		String auctionDate = (String) this.get("txtAuctionDate");
		String auctionDuration = (String) this.get("txtAuctionDuration");
		String auctionfirstPrice = (String) this.get("txtAuctionfirstPrice");
		String auctionWantedPrice = (String) this.get("txtAuctionWantedPrice");
		ActionErrors errors = new ActionErrors();

		if (auctionDate == null || auctionDate.trim().equals("")) 
		{
			errors.add("auctionDateVide", new ActionMessage(
			"AjoutProduit.particulier.auctionDate.vide"));
		} 
		else if (!auctionDate.matches("(\\d){2}/(\\d){2}/(\\d){4}")) 
			{
				errors.add("auctionDateIncorect", new ActionMessage(
				"AjoutProduit.particulier.auctionDate.Incorect"));
			}
		if (auctionDuration == null || auctionDuration.trim().equals("")) 
		{
			errors.add("auctionDurationVide", new ActionMessage(
			"AjoutProduit.particulier.auctionDuration.vide"));
		} 
		else if (!auctionDuration.matches("(\\d)+")) 
			{
				errors.add("auctionDurationIncorect", new ActionMessage(
				"AjoutProduit.particulier.duration.Incorect"));
			}
		if (auctionfirstPrice == null || auctionfirstPrice.trim().equals("")) 
		{
			errors.add("auctionfirstPriceVide", new ActionMessage(
			"AjoutProduit.particulier.auctionfirstPrice.vide"));
		} 
		else if (!auctionfirstPrice.matches("(\\d)+\\.(\\d)+||(\\d)+")) 
			{
				errors.add("auctionfirstPriceIncorect", new ActionMessage(
				"AjoutProduit.particulier.price.Incorect"));
			}
		if (auctionWantedPrice == null || auctionWantedPrice.trim().equals("")) 
		{
			errors.add("auctionWantedPriceVide", new ActionMessage(
			"AjoutProduit.particulier.auctionWantedPrice.vide"));
		} 
		else if (!auctionWantedPrice.matches("(\\d)+\\.(\\d)+||(\\d)+")) 
			{
				errors.add("auctionWantedPriceIncorect", new ActionMessage(
				"AjoutProduit.particulier.price.Incorect"));
			}
		return errors;
	}
}